/*
 * InitLoginActivity.java
 *
 * Copyright(c) IronOne Technologies (Pvt) Ltd.  All Rights Reserved.
 * This software is the proprietary information of IronOne Technologies (Pvt) Ltd.
 *
 */
package com.ironone.streaming;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

import android.content.Intent;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.content.pm.Signature;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.util.Base64;
import android.util.Log;
import android.view.View;

import com.ironone.streaming.application.CusAlrtBtnTypes;
import com.ironone.streaming.application.CusAlrtIconTypes;
import com.ironone.streaming.application.CustomAlertDialog;
import com.ironone.streaming.exception.ExceptionHandler;
import com.ironone.streaming.lite.R;

/**
 * {This class shows the Login window screen for the user}
 * 
 * @Created on May 21, 2014 : 3:18:00 PM
 * @author Suren Manawatta
 */
public class InitLoginActivity extends FragmentActivity {

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		try {
			super.onCreate(savedInstanceState);
			Thread.setDefaultUncaughtExceptionHandler(new ExceptionHandler(this));
			//overridePendingTransition(R.anim.slide_right_to_middle, R.anim.slide_middle_to_left);
			//overridePendingTransition(R.animator.activity_translate_anim1,R.animator.activity_translate_anim2);
			MainFragment mainFragment;

			if (savedInstanceState == null) {
				// Add the fragment on initial activity setup
				mainFragment = new MainFragment();
				getSupportFragmentManager().beginTransaction()
				.add(android.R.id.content, mainFragment)
				.commit();
			} else {
				// Or set the fragment from restored state info
				mainFragment = (MainFragment) getSupportFragmentManager()
						.findFragmentById(android.R.id.content);
			}			
			getKeyHash();
		} catch (Exception e) {
			CustomAlertDialog alertDialog = new CustomAlertDialog(this, CusAlrtBtnTypes.OK, CusAlrtIconTypes.DUCK);
			alertDialog.setTitleText(getString(R.string.what_the_duck_));
			//alertDialog.setMessageText(getString(R.string.something_snapped));			
			alertDialog.show();
		}
	}

	public void onClick_continueWithoutFacebbok(View view) {
		try {
			Log.e("On click without facebook success","fsfsfs");
			/**Intent i = new Intent(InitLoginActivity.this, RadioPlayerActivity.class);
			
			startActivity(i);
			i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
			overridePendingTransition(R.anim.slide_right_to_middle, R.anim.slide_middle_to_left);*/
			Intent i = new Intent(InitLoginActivity.this, RadioPlayerActivity.class);
			startActivity(i);
			 //Helani
            //overridePendingTransition(R.animator.activity_translate_anim1, R.animator.activity_translate_anim2);
			finish();
		} catch (Exception e) {
			CustomAlertDialog alertDialog = new CustomAlertDialog(this, CusAlrtBtnTypes.OK, CusAlrtIconTypes.DUCK);
			alertDialog.setTitleText(getString(R.string.what_the_duck_));
			//alertDialog.setMessageText(getString(R.string.something_snapped));			
			alertDialog.show();
		}
	}

	private void getKeyHash()
	{
		try {
			PackageInfo info = getPackageManager().getPackageInfo(
					"com.ironone.streaming", 
					PackageManager.GET_SIGNATURES);
			for (Signature signature : info.signatures) {
				MessageDigest md = MessageDigest.getInstance("SHA");
				md.update(signature.toByteArray());
				Log.e("KeyHash:", Base64.encodeToString(md.digest(), Base64.DEFAULT));
				Log.e("KeyHash:", Base64.encodeToString(md.digest(), Base64.DEFAULT));
			}
		} catch (NameNotFoundException e) {
		} catch (NoSuchAlgorithmException e) {
		} catch (Exception e) {
		}
	}
}
